package com.the12354.orena;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Timer;

public class OrenaPlugin extends JavaPlugin {

	private Timer m_Timer = new Timer(true);
	private OrenaEntityListener entityListener = new OrenaEntityListener(this);
	OrenaMaster master;
	private static String Version = "0.2.1";
	public void onEnable() {
		PluginManager pm = getServer().getPluginManager();
		pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener,Event.Priority.Monitor, this);
		pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener,Event.Priority.Monitor, this);
		pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener,Event.Priority.Monitor, this);
		
		master = new OrenaMaster(getServer());
		this.m_Timer.schedule(new OrenaTimer(this), 0, 1000);
		System.out.println("[Orena] Version " + Version + " geladen!");
	}

	public void onDisable() {
		master.onDisable();
	}

	public void onDeath(int entID) {
		master.onDeath(entID);
	}

	public void onDamage(int ent, int damager) {
		master.onDamage(ent, damager);
	}

	public void onDamage(Entity ent, Entity damager) {
		master.onDamage(ent.getEntityId(), damager.getEntityId());
	}

	public boolean onCommand(CommandSender sender, Command cmd,String commandLabel, String[] args) {
		/*if (commandLabel.equalsIgnoreCase("orena")) {
			sender.sendMessage("/orena");
			return true;
		}*/
		return false;
	}

	public void Tick() {
		master.Tick();
	}
}